﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using MySql.Data.MySqlClient;
using DateBaseConnectionPool;
using System.Data;

namespace TestMySqlConnetPoll
{
    
    public class objLkKey
    {
        public DateTime time;
        public int No;
    }

    public class LK_Table
    {
        #region  外部函数定义 变量定义 列控

//        public Dictionary<objLkKey, objLKHostHardTable> HostHardwarePlatform = new Dictionary<objLkKey, objLKHostHardTable>();
        public DataSet HostHardwarePlatformSet = new DataSet("列控中心主机硬件平台");
        //public DataTable HostHardwarePlatform = new DataTable("列控中心主机硬件平台");
        public DataTable LianSuoJieKouRouteInfo = new DataTable("列控中心与联锁接口进路信息");
        public DataTable LianSuoGaiFangCommandInfo = new DataTable("列控中心与联锁改方命令信息");
        public DataTable LianSuoGaiFangCommandRet = new DataTable("列控中心与联锁改方回执信息");
        public DataTable ZhanJianGaiFangCommandInfo = new DataTable("列控中心站间改方命令信息");
        public DataTable ZhanJianGaiFangCommandRet = new DataTable("列控中心站间改方回执信息");
        public DataTable ZhanJianBoundaryInfo = new DataTable("列控中心站间边界信息");
        public DataTable SendToLianSuoInfo = new DataTable("发送给联锁的无配线站区间方向口信息");
        public DataTable TemporaryLimitSpeedState = new DataTable("列控中心临时限速状态");
//        public DataTable SectionEncodeInfo = new DataTable("轨道区段编码信息");
        public DataSet SectionEncodeInfo = new DataSet("轨道区段编码信息");
        public DataTable TransponderEncodeInfo = new DataTable("应答器报文编码信息");

        public Dictionary<DateTime, DataSet> AllStatueInfo = new Dictionary<DateTime, DataSet>();   //全体状态信息

        public void InitLKTable()
        {
            c_LK.InitLianSuoGaiFangCommandInfo(ref LianSuoGaiFangCommandInfo);
            c_LK.InitLianSuoGaiFangCommandRet(ref LianSuoGaiFangCommandRet);
            c_LK.InitLianSuoJieKouRouteInfo(ref LianSuoJieKouRouteInfo);
            //c_LK.InitSectionEncodeInfo(ref SectionEncodeInfo);
            c_LK.InitSendToLianSuoInfo(ref SendToLianSuoInfo);
            c_LK.InitTemporaryLimitSpeedState(ref TemporaryLimitSpeedState);
            c_LK.InitTransponderEncodeInfo(ref TransponderEncodeInfo);
            c_LK.InitZhanJianBoundaryInfo(ref ZhanJianBoundaryInfo);
            c_LK.InitZhanJianGaiFangCommandInfo(ref ZhanJianGaiFangCommandInfo);
            c_LK.InitZhanJianGaiFangCommandRet(ref ZhanJianGaiFangCommandRet);
        }

        /// <summary>
        /// 以列控类型做键值
        /// </summary>
        private int LkType = -1;    //列控类型
        public List<ObjLK> ValueList = new List<ObjLK>();

        private bool ReadyValueList = false;    //读数据库准备好
        public bool ReadyDataTable = false;     //DataTable准备好
        public int ErrorFlag = 0;
        public bool ReadyTime = false;
        public int MaxTime = 0;     //终端用的最大时间
        public int MinTime = 0;     //终端用的最小时间

        public struct LkThreadStruct
        {
            public string TableName;
            public int s_time;
            public int e_time;
            public int type;
            public byte p_day;
        }
        /// <summary>
        /// 读取列控历史信息开始时间和结束时间
        /// </summary>
        /// <param name="protecol"></param>
        public void ReadTimeList(int protecol)
        {
            ReadyTime = false;
            ErrorFlag = 0;
            MinTime = 0;
            MaxTime = 0;

            LkThreadStruct obj = new LkThreadStruct();
            obj.TableName = "LK_Table";
            obj.type = protecol;
            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadReadLK_TimeList), obj);
        }

        //硬件平台信息回放，按秒读取
        public void ReadValueList(Int32 s_time, Int32 e_time, string TypeName)
        {
            ReadyValueList = false;
            LkThreadStruct obj = new LkThreadStruct();
            obj.TableName = "LK_Table";
            obj.s_time = s_time;
            obj.e_time = e_time;
            obj.type = c_LK.GetLkProtecolNo(TypeName);
            LkType = obj.type;
            ValueList.Clear();
            if (obj.type == -1)
            {
                ErrorFlag = 1;
            }
            else
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadReadLK_ValueList), obj);
                ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadOrganizeDataTable), obj);
            }
        }

        //按天读取数据
        public void ReadValueList(DateTime p_day, string TypeName)
        {
            ReadyValueList = false;
            ReadyDataTable = false;
            LkThreadStruct obj = new LkThreadStruct();
            obj.TableName = "LK_Table";
            obj.p_day = (byte)p_day.Day;
            obj.s_time = MySql.DateTimeToTime_t(new DateTime(p_day.Year, p_day.Month, p_day.Day, 0, 0, 0));
            obj.e_time = MySql.DateTimeToTime_t(new DateTime(p_day.Year, p_day.Month, p_day.Day, 23, 59, 59));
            LkType = c_LK.GetLkProtecolNo(TypeName);
            obj.type = LkType;
            ValueList.Clear();
            if (obj.type == -1)
            {
                ErrorFlag = 1;
            }
            else
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadReadLK_ValueList_pday), obj);
                ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadOrganizeDataTable), obj);
            }
        }

        private void ThreadOrganizeDataTable(object o)
        {
            LkThreadStruct obj = (LkThreadStruct)o;
            string TypeName = c_LK.GetLkTypeName(obj.type);
            while (true)
            {
                if (ErrorFlag != 0) break;
                if (ReadyValueList)
                {
                    if (TypeName == "列控中心主机硬件平台")     //列控中心主机硬件平台
                    {
                        for (int i = 0; i < ValueList.Count; i++)
                        {
                            DataTable dt = new DataTable(i.ToString());
                            c_LK.InitHostHardwarePlatform(ref dt);

                            c_LK.ParseProtecol_HostHardwarePlatform(ref dt, ValueList[i].lkAValue);
                            c_LK.ParseProtecol_HostHardwarePlatform(ref dt, ValueList[i].lkBValue);
                            HostHardwarePlatformSet.Tables.Add(dt);     //以序号作为表头，回放时一秒以帧回放，时间信息直接在表头里面
                        }
                    }
                    else if (TypeName == "列控中心与联锁接口进路信息")
                    {
                        c_LK.ParseProtecol_LianSuoJieKouRouteInfo(ref LianSuoJieKouRouteInfo, ValueList);
                    }
                    else if (TypeName == "列控中心与联锁改方命令信息")
                    {
                        c_LK.ParseProtecol_LianSuoGaiFangCommandInfo(ref LianSuoGaiFangCommandInfo, ValueList);
                    }
                    else if (TypeName == "列控中心与联锁改方回执信息")
                    {
                        c_LK.ParseProtecol_LianSuoGaiFangCommandRet(ref LianSuoGaiFangCommandRet, ValueList);
                    }
                    else if (TypeName == "列控中心站间改方命令信息")
                    {
                        c_LK.ParseProtecol_ZhanJianGaiFangCommandInfo(ref ZhanJianGaiFangCommandInfo, ValueList);
                    }
                    else if (TypeName == "列控中心站间改方回执信息")
                    {
                        c_LK.ParseProtecol_ZhanJianGaiFangCommandRet(ref ZhanJianGaiFangCommandRet, ValueList);
                    }
                    else if (TypeName == "列控中心站间边界信息")
                    {
                        c_LK.ParseProtecol_ZhanJianBoundaryInfo(ref ZhanJianBoundaryInfo, ValueList);
                    }
                    else if (TypeName == "发送给联锁的无配线站区间方向口信息")
                    {
                        c_LK.ParseProtecol_SendToLianSuoInfo(ref SendToLianSuoInfo, ValueList);
                    }
                    else if (TypeName == "列控中心临时限速状态")
                    {
                        c_LK.ParseProtecol_TemporaryLimitSpeedState(ref TemporaryLimitSpeedState, ValueList);
                    }
                    else if (TypeName == "轨道区段编码信息")    //轨道区段编码信息
                    {
                        foreach (ObjLK key in ValueList)
                        {
                            string Tname = MySql.Time_tToDateTime(key.u_time).ToString();
                            DataTable dt = new DataTable(Tname);
                            c_LK.InitSectionEncodeInfo(ref dt);
                            c_LK.ParseProtecol_SectionEncodeInfo(ref dt, key.lkAValue.ToArray());
                            SectionEncodeInfo.Tables.Add(dt);
                        }
                    }
                    else if (TypeName == "状态信息")    //状态信息
                    {
                        foreach (ObjLK key in ValueList)
                        {
                            DataSet ds = new DataSet("状态全体信息");
                            c_LK.InitStatueInfo(ref ds);
                            DateTime d = MySql.Time_tToDateTime(key.u_time);
                            c_LK.ParaseProtecol_AllStatueInfo(ref ds, key.lkAValue.ToArray());
                            AllStatueInfo.Add(d, ds);   //加入到字典中，以时间为键值，回放时以此时间作为显示
                        }
                    }
                    else if (TypeName == "应答器报文编码信息")    //应答器报文编码信息
                    {
                        c_LK.ParaseProtecol_TransponderEncodeInfo(ref TransponderEncodeInfo, ValueList);
                    }
                    else if (TypeName == "维护中心报警数据")    //维护中心报警数据
                    {
                        //该项在报警里面，不在回放信息里
                    }
                    ReadyDataTable = true;
                    break;
                }
                else Thread.Sleep(20);
            }
        }

        #endregion
        private Mutex keyMutex = new Mutex();
        static private int keykey = 0;
        #region 列控
        private void ThreadReadLK_TimeList(object o)
        {
            LkThreadStruct obj = (LkThreadStruct)o;
            string TableName = obj.TableName;
            int type = obj.type;
            if (MySql.c != null && MySql.c.State == PoolState.Run)
            {
                MySqlConnection con = new MySqlConnection();
                string key = TableName + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + Interlocked.Increment(ref keykey).ToString();
                try
                {
                    con = (MySqlConnection)MySql.c.GetConnectionFormPool(key);
                }
                catch (MySqlException ex)
                {
                    //写异常日志
                    ErrorFlag = 2;
                }
                if (con != null)
                {
                    try
                    {
                        StringBuilder SelectStatement = new StringBuilder();
                        SelectStatement.Append(string.Format("SELECT MIN(u_time) as mintime from {0} where type = {1}", TableName, type));
                        MySqlCommand selectCommand = new MySqlCommand(SelectStatement.ToString(), con);
                        selectCommand.CommandTimeout = 120;   //120s操作超时

                        MySqlDataReader read = selectCommand.ExecuteReader();
                        while (read.Read())
                        {
                            if (!read.IsDBNull(read.GetOrdinal("mintime")))
                                MinTime = read.GetInt32(read.GetOrdinal("mintime"));
                        }
                        read.Close();

                        StringBuilder SelectMaxStatement = new StringBuilder();
                        SelectMaxStatement.Append(string.Format("SELECT MAX(u_time) as maxtime from {0} where type = {1}", TableName,type));
                        MySqlCommand selectMaxCommand = new MySqlCommand(SelectMaxStatement.ToString(), con);
                        selectMaxCommand.CommandTimeout = 120;   //120s操作超时

                        MySqlDataReader readMax = selectMaxCommand.ExecuteReader();
                        while (readMax.Read())
                        {
                            if (!readMax.IsDBNull(readMax.GetOrdinal("maxtime")))
                                MaxTime = readMax.GetInt32(readMax.GetOrdinal("maxtime"));
                        }
                        readMax.Close();
                        ReadyTime = true;
                    }
                    catch (MySqlException e)
                    {
                        ErrorFlag = 3;
                    }
                    try
                    {
                        MySql.c.DisposeConnection(key);
                    }
                    catch (MySqlException e)
                    {
                        ErrorFlag = 4;
                    }
                }
                else ErrorFlag = 5;
            }
            else ErrorFlag = 6;
        }
        /// <summary>
        /// 插入列控数据
        /// </summary>
        /// <param name="TableName"></param>
        /// <param name="p_day"></param>
        /// <param name="type"></param>
        /// <param name="u_time"></param>
        /// <param name="len"></param>
        /// <param name="lkValue"></param>
        /// <returns></returns>
        public bool InsertLK_Table(byte p_day, byte type, Int32 u_time,int abflag,int zbflag, Int16 len, byte[] lkAValue,byte[] lkBValue)
        {
            bool tmpFlag = false;
            string TableName = "lk_table";
            if (TableName == "") return tmpFlag;
            if (MySql.c != null && MySql.c.State == PoolState.Run)
            {
                MySqlConnection con = new MySqlConnection();
                string key = TableName + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + Interlocked.Increment(ref keykey).ToString();
                try
                {
                    con = (MySqlConnection)MySql.c.GetConnectionFormPool(key);
                }
                catch (MySqlException ex)
                {
                    //写异常日志
                    tmpFlag = false;
                }
                
                if (con != null)
                {
                    StringBuilder InsertStatement = new StringBuilder();

                    InsertStatement.Append(string.Format("insert into {0} (p_day,u_time,type,abflag,zbflag,len,lkAValue,lkbvalue)", TableName));

                    InsertStatement.Append("values(?p_day,?u_time,?type,?abflag,?zbflag,?len,?lkavalue,?lkbvalue)");

                    MySqlCommand InsertCommand = new MySqlCommand(InsertStatement.ToString(), con);
                    InsertCommand.Parameters.Add(new MySqlParameter("?p_day", MySqlDbType.Byte)).Value = p_day;
                    InsertCommand.Parameters.Add(new MySqlParameter("?u_time", MySqlDbType.UInt32)).Value = u_time;
                    InsertCommand.Parameters.Add(new MySqlParameter("?type", MySqlDbType.Byte)).Value = type;
                    InsertCommand.Parameters.Add(new MySqlParameter("?abflag", MySqlDbType.Byte)).Value = abflag;
                    InsertCommand.Parameters.Add(new MySqlParameter("?zbflag", MySqlDbType.Byte)).Value = zbflag;
                    InsertCommand.Parameters.Add(new MySqlParameter("?len", MySqlDbType.Int16)).Value = len;
                    InsertCommand.Parameters.Add(new MySqlParameter("?lkavalue", MySqlDbType.VarBinary)).Value = lkAValue.ToArray();
                    InsertCommand.Parameters.Add(new MySqlParameter("?lkbvalue", MySqlDbType.VarBinary)).Value = lkBValue.ToArray();

                    try
                    {
                        int k = InsertCommand.ExecuteNonQuery();
                        if (k == 1) tmpFlag = true;        //写入成功
                        else tmpFlag = false;              //写入失败
                    }
                    catch (MySqlException e)
                    {
                        //写异常日记
                        tmpFlag = false;       //写入失败
                    }
                    try
                    {
                        MySql.c.DisposeConnection(key);
                    }
                    catch (MySqlException e)
                    {
                        //写异常日记
                    }
                }
            }
            return tmpFlag;
        }

        private void ThreadReadLK_ValueList(object o)
        {
            LkThreadStruct obj = (LkThreadStruct)o;

            string TableName = obj.TableName;
            Int32 s_time = obj.s_time;
            Int32 e_time = obj.e_time;
            byte type = (byte)obj.type;
            string typeStr = c_LK.GetLkTypeName(type);
            bool OneDay = true;         //开始时间和结束时间是否在同一天内
            int p_day = 0;             //第一天的天
            int sencond_day = 0;       //第二天的天

            DateTime st = MySql.Time_tToDateTime(s_time);
            DateTime et = MySql.Time_tToDateTime(e_time);

            if (st.Day == et.Day)
            {
                OneDay = true;
                p_day = st.Day;
            }
            else
            {
                OneDay = false;
                p_day = st.Day;
                sencond_day = et.Day;
            }


            if (MySql.c != null && MySql.c.State == PoolState.Run)
            {
                MySqlConnection con = new MySqlConnection();
                string key = TableName + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + Interlocked.Increment(ref keykey).ToString();
                try
                {
                    con = (MySqlConnection)MySql.c.GetConnectionFormPool(key);
                }
                catch (MySqlException ex)
                {
                    //写异常日志
                    ErrorFlag = 2;
                }
                if (con != null)
                {
                    StringBuilder SelectStatement = new StringBuilder();
                    if (OneDay) //在一天内
                    {
                        if (typeStr == "列控中心主机硬件平台")    //硬件平台
                        {
                            SelectStatement.Append(string.Format("select no,u_time,ABFlag,ZBFlag,len,lkAValue,lkBValue from {0} where p_day={1} and u_time>={2} and u_time<={3} and type = {4}", TableName, p_day, s_time, e_time, type));
                        }
                        else
                        {
                            SelectStatement.Append(string.Format("select no,u_time,ABFlag,ZBFlag,len,lkAValue from {0} where p_day={1} and u_time>={2} and u_time<={3} and type = {4}", TableName, p_day, s_time, e_time, type));
                        }
                    }
                    else   //跨分区查询
                    {
                        if (type == 0x50)   //硬件平台
                        {
                            SelectStatement.Append(string.Format("select no,u_time,ABFlag,ZBFlag,len,lkAValue,lkBValue from {0} where p_day={1} or p_day ={2} and u_time>={3} and u_time<={4} and type = {5}", TableName, p_day, sencond_day, s_time, e_time, type));
                        }
                        else
                        {
                            SelectStatement.Append(string.Format("select no,u_time,ABFlag,ZBFlag,len,lkAValue from {0} where p_day={1} or p_day ={2} and u_time>={3} and u_time<={4} and type = {5}", TableName, p_day, sencond_day, s_time, e_time, type));
                        }
                    }
                    try
                    {
                        MySqlCommand selectCommand = new MySqlCommand(SelectStatement.ToString(), con);
                        selectCommand.CommandTimeout = 120;   //120s操作超时

                        MySqlDataReader read = selectCommand.ExecuteReader();
                        while (read.Read())
                        {
                            ObjLK k = new ObjLK();
                            k.No = read.GetInt32(read.GetOrdinal("no"));
                            k.ABflag = (byte)read.GetInt32(read.GetOrdinal("ABFlag"));
                            k.ZBflag = (byte)read.GetInt32(read.GetOrdinal("ZBFlag"));
                            k.u_time = read.GetInt32(read.GetOrdinal("u_time"));
                            k.len = read.GetInt16(read.GetOrdinal("len"));
                            read.GetBytes(read.GetOrdinal("lkAValue"), 0, k.lkAValue, 0, k.len);
                            if (typeStr == "列控中心主机硬件平台")
                            {
                                read.GetBytes(read.GetOrdinal("lkBValue"), 0, k.lkBValue, 0, k.len);
                            }
                            ValueList.Add(k);
                        }
                        read.Close();
                        ReadyValueList = true;
                    }
                    catch (MySqlException e)
                    {
                        ErrorFlag = 3;
                    }

                    try
                    {
                        MySql.c.DisposeConnection(key);
                    }
                    catch (MySqlException e)
                    {
                        ErrorFlag = 4;
                    }
                }
                else ErrorFlag = 6;
            }
            else ErrorFlag = 7;
        }

        private void ThreadReadLK_ValueList_pday(object o)
        {
            LkThreadStruct obj = (LkThreadStruct)o;
            string TableName = obj.TableName;
            byte p_day = obj.p_day;
            byte type = (byte)obj.type;
            string typeStr = c_LK.GetLkTypeName(type);

            if (MySql.c != null && MySql.c.State == PoolState.Run)
            {
                MySqlConnection con = new MySqlConnection();
                string key = TableName + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + Interlocked.Increment(ref keykey).ToString();
                try
                {
                    con = (MySqlConnection)MySql.c.GetConnectionFormPool(key);
                }
                catch (MySqlException ex)
                {
                    //写异常日志
                    ErrorFlag = 2;
                }
                if (con != null)
                {
                    StringBuilder SelectStatement = new StringBuilder();

                    if (typeStr == "列控中心主机硬件平台")    //硬件平台
                    {
                        SelectStatement.Append(string.Format("select no,u_time,ABFlag,ZBFlag,len,lkAValue,lkBValue from {0} where p_day={1} and type = {2}", TableName, p_day,  type));
                        SelectStatement.Append(string.Format(" and u_time >= {0} and u_time <= {1}", obj.s_time, obj.e_time));
                    }
                    else
                    {
                        SelectStatement.Append(string.Format("select no,u_time,ABFlag,ZBFlag,len,lkAValue from {0} where p_day={1} and type = {2}", TableName, p_day, type));
                        SelectStatement.Append(string.Format(" and u_time >= {0} and u_time <= {1}", obj.s_time, obj.e_time));
                    }

                    //SelectStatement.Append(string.Format("select(no,ABFlag,ZBFlag,len,lkValue) from{0} where p_day={1} and type = {2}", TableName, p_day, type));

                    try
                    {
                        MySqlCommand selectCommand = new MySqlCommand(SelectStatement.ToString(), con);
                        selectCommand.CommandTimeout = 120;   //120s操作超时

                        MySqlDataReader read = selectCommand.ExecuteReader();
                        while (read.Read())
                        {
                            ObjLK k = new ObjLK();
                            k.No = read.GetInt32(read.GetOrdinal("no"));
                            k.ABflag = (byte)read.GetInt32(read.GetOrdinal("ABFlag"));
                            k.ZBflag = (byte)read.GetInt32(read.GetOrdinal("ZBFlag"));
                            k.u_time = read.GetInt32(read.GetOrdinal("u_time"));
                            k.len = read.GetInt16(read.GetOrdinal("len"));
                            read.GetBytes(read.GetOrdinal("lkAValue"), 0, k.lkAValue, 0, k.len);
                            if (typeStr == "列控中心主机硬件平台")
                            {
                                read.GetBytes(read.GetOrdinal("lkBValue"), 0, k.lkBValue, 0, k.len);
                            }
                            ValueList.Add(k);
                        }
                        read.Close();
                        ReadyValueList = true;
                    }
                    catch (MySqlException e)
                    {
                        ErrorFlag = 3;
                    }

                    try
                    {
                        MySql.c.DisposeConnection(key);
                    }
                    catch (MySqlException e)
                    {
                        ErrorFlag = 4;
                    }
                }
                else ErrorFlag = 5;
            }
            else ErrorFlag = 6;
        }

        //private void Add_LkTimeList(byte p_day)
        //{
        //    objDate t = new objDate();
        //    t.year = DateTime.Now.Year;
        //    t.month = (byte)DateTime.Now.Month;
        //    t.day = p_day;

        //    if (p_day <= DateTime.Now.Day) //当前月
        //    {
        //        if (TimeList.Contains(t)) { }
        //        else TimeList.Add(t);
        //    }
        //    else //上月数据
        //    {
        //        if (DateTime.Now.Month != 1)  //不是一月，不需要跨年
        //        {
        //            t.month = t.month--;
        //            if (TimeList.Contains(t)) { }
        //            else TimeList.Add(t);
        //        }
        //        else
        //        {
        //            t.year--;
        //            t.month--;
        //            if (TimeList.Contains(t)) { }
        //            else TimeList.Add(t);
        //        }
        //    }
        //}

        //private void ThreadReadLK_TimeList(object o)
        //{
        //    string TableName = "LK_Table";
        //    if (TableName == "") return;
        //    if (MySql.c != null && MySql.c.State == PoolState.Run)
        //    {
        //        MySqlConnection con = new MySqlConnection();
        //        string key = TableName + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString()+ (MySql.key++).ToString();
        //        try
        //        {
        //            con = (MySqlConnection)MySql.c.GetConnectionFormPool(key);
        //        }
        //        catch (MySqlException ex)
        //        {
        //            //写异常日志
        //        }
        //        if (con != null)
        //        {
        //            StringBuilder SelectStatement = new StringBuilder();

        //            SelectStatement.Append(string.Format("select(p_day) from{0}", TableName));

        //            try
        //            {
        //                MySqlCommand selectCommand = new MySqlCommand(SelectStatement.ToString(), con);
        //                selectCommand.CommandTimeout = 120;   //120s操作超时

        //                MySqlDataReader read = selectCommand.ExecuteReader();
        //                while (read.Read())
        //                {
        //                    byte p_day = read.GetByte(read.GetOrdinal("p_day"));
        //                    Add_LkTimeList(p_day);
        //                }
        //                read.Close();
        //                ReadyTimeList = true;
        //            }
        //            catch (MySqlException e)
        //            {
        //                //写错误日志
        //            }
        //            try
        //            {
        //                MySql.c.DisposeConnection(key);
        //            }
        //            catch (MySqlException e)
        //            {
        //                //写错误日志
        //            }
        //        }
        //    }
        //}
        #endregion
    }
}
